import {reqGoodsInfo,reqAddOrUpdateShopCart} from '@/api'
import {getUUID} from '@/untils/uuid_token'
const state = {
    goodsInfo:{},
    uuid_token:getUUID()
}
const mutations ={
    GETGOODINFO(state,goodsInfo){
        state.goodsInfo = goodsInfo
    }
};
const actions = {
    async getGoodInfo({commit},skuId){
        let result = await reqGoodsInfo(skuId)
       if (result.code == 200) {
        commit('GETGOODINFO',result.data)
       }
       },
    async goSuccess({commit},{skuId,skuNum}){
         await reqAddOrUpdateShopCart(skuId,skuNum)
         console.log(111);
        // if (result.code == 200) {
        //     return 'ok'
        //   }else {
        //     return Promise.reject(result.message)
        //   }
    }

};
const getters = {
    categoryView(state){
        return state.goodsInfo.categoryView || {}
    },
    skuInfo(state){
        return state.goodsInfo.skuInfo || {}
    },
    spuSaleAttrList(state){
        return state.goodsInfo.spuSaleAttrList || []
    },
}

export default{
    state,
    mutations,
    actions,
    getters
}